


	$(document).ready(function(){
//		alert(123);
		getTime();
		setInterval(function(){
			getTime();
		},1000);
		getAge();
		getBirthday();
		clicks();
		del_Button();
		
		
	});
		
	
		function del_Button2(){
			$("#del-button").click(function(){	
				var username = $("#del-username").val();
				var password = $("#del-password").val();
				if(password != ""){
					$.post(
							"/cn.yl.caner/checkPassword",
							{"password": password ,
								"username": username},
							function(data){
								var Password = data.isPassword;
								var passwordInfo = "";
								if(Password){
									passwordInfo = "密码正确";
									return false;
								}else{
									passwordInfo = "密码错误"
									$("#span-password").html(passwordInfo);
									return false;
								}
								$("#span-password").html(passwordInfo);
							},
							"json"
						);	
					}else{
						return false;
					}
			});
		}
	
		function clicks(){
			// alert("nihao");
			var change = 0;
			var del = 0;
			var find = 0;
			var add = 0;
			var index = 1;
			$('#account-change').click(function(){
				// alert("nihao" );
				if(change != 1){
					change = 1;
					del = 0;
					find = 0;
				    add = 0;
					index = 0;
					$('#show-change').show();
					$('#show-del').hide();
					$('#show-find').hide();
					$('#show-add').hide();
					$('#show-index').hide();
					// change = 0;
				}else {
					change = 0;
					del = 0;
					find = 0;
					add = 0;
					index = 1;
					$('#show-change').hide();
					$('#show-del').hide();
					$('#show-find').hide();
					$('#show-add').hide();
					$('#show-index').show();
				}
			});
			$('#account-del').click(function(){
				// alert("nihao" );
				if(del != 1){
					change = 0;
					del = 1;
					find = 0;
					add = 0;
					index = 0;
					$('#show-change').hide();
					$('#show-del').show();
					$('#show-find').hide();
					$('#show-add').hide();
					$('#show-index').hide();
					// del = 0;
				}else {
					change = 0;
					del = 0;
					find = 0;
					add = 0;
					index = 1;
					$('#show-change').hide();
					$('#show-del').hide();
					$('#show-find').hide();
					$('#show-add').hide();
					$('#show-index').show();
				}
			});
			$('#account-find').click(function(){
				// alert("nihao" );
				if(find != 1){
					change = 0;
					del = 0;
					find = 1;
					add = 0;
					index = 0;
					$('#show-change').hide();
					$('#show-del').hide();
					$('#show-find').show();
					$('#show-add').hide();
					$('#show-index').hide();
					// find= 0;
				}else {
					change = 0;
					del = 0;
					find = 0;
					add = 0;
					index = 1;
					$('#show-change').hide();
					$('#show-del').hide();
					$('#show-find').hide();
					$('#show-add').hide();
					$('#show-index').show();
				}
			});
			$('#account-add').click(function(){
				 // alert("nihao" );
				if(add != 1){
					change = 0;
					del = 0;
					find = 0;
					add = 1;
					index = 0;
					$('#show-change').hide();
					$('#show-del').hide();
					$('#show-find').hide();
					$('#show-add').show();
					$('#show-index').hide();
					// add = 0;
				}else {
					change = 0;
					del = 0;
					find = 0;
					add = 0;
					index = 1;
					$('#show-change').hide();
					$('#show-del').hide();
					$('#show-find').hide();
					$('#show-add').hide();
					$('#show-index').show();
				}
			});
		}
			//生日显示算法
			function getBirthday(){
				// alert("jkj");
				var date = new Date();
				var year = date.getFullYear();
				for(var i =year-100; i<=year; i++){
					$("#add-birthday-year").append("<option value=\""+i+"\">"+i+"</option>");	
				}
				for(var i=1; i<=12; i++){
					$("#add-birthday-month").append("<option value=\""+i+"\">"+i+"</option>");
				}
				getDays($("#add-birthday-month").val(),$("#add-birthday-year").val());
				return year;
			}
			
			function getDaysInMonths(month,year){
				var days;
				if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
					days = 31;
				}else if(month==4 || month==6 || month==9 || month==11){
					days = 30;
				}else{
					if((year%4 == 0 && year%100 != 0) || (year%400 == 0)){
						days = 29;
					}else{
						days = 28;
					}
				}
				// $("#add-birthday-day").append("<option value=\""+days+"\">"+days+"</option>")
				return days;
			}
			
			function getDays(month,year){
				var year = $("#add-birthday-year" ).val();
				// $("#add-birthday-day").append("<option value=\""+year+"\">"+year+"</option>")
				var month =$("#add-birthday-month").val();
				// $("#add-birthday-day").append("<option value=\""+month+"\">"+month+"</option>")
				var days = getDaysInMonths(month,year);
				// $("#add-birthday-day").append("<option value=\""+year+"\">"+year+"</option>")
				// $("#add-birthday-day").append("<option value=\""+month+"\">"+month+"</option>")
				// $("#add-birthday-day").empty();
				for(var i =1; i<=days; i++){
					$("#add-birthday-day").append("<option value=\""+i+"\">"+i+"</option>")
				}
			}
			
			//年龄算法
			function getAge(){

				var now = getBirthday();
				var birthyear = 1919;
				var age = now - birthyear;
				// $("#add-age").append("<option value=\""+i+"\">"+age+"</option>")
				for(var i=0; i<=age;i++){
					$("#add-age").append("<option value=\""+i+"\">"+i+"</option>");
				}
			}
			
			//获取系统时间
			
			function getTime(){
				var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth();
				var day = date.getDate();
				var hour = date.getHours();
				var minu = date.getMinutes();
				var sec = date.getSeconds();
				if(minu<10){
					minu = "0"+minu;
				}
				if(sec<10){
					sec = "0"+sec;
				}
				var time = year+"年"+month+"月"+day+"日"+hour+":"+minu+":"+sec;
				// alert(time);
				$("#span-time").html(time);
			}

			
			function isDel(){
				var username = $("#del-username").val();
//			    alert(username);
				if(username != "" ){
				$.post(
					"/cn.yl.caner/check",
					{"username": username },
					function(data){
						var isUsername = data.isUsername;
						var usernameInfo = "";
						if(isUsername){
							usernameInfo = "该用户存在";
						}else{
							usernameInfo = "该用户不存在"
						}
						$("#span-account").html(usernameInfo);
					},
					"json"
				);	
				}else{
					
				}
			}
	
			function isPassword(){
//				alert(123);
				var username = $("#del-username").val();
				var password = $("#del-password").val();
				if(password != ""){
//					alert(123);
					$.post(
							"/cn.yl.caner/checkPassword",
							{"password": password ,
								"username": username},
							function(data){
								var Password = data.isPassword;
								var passwordInfo = "";
								if(Password){
									passwordInfo = "密码正确";
									$("#span-password").html(passwordInfo);
									return true;
								}else{
									passwordInfo = "密码错误"
									$("#span-password").html(passwordInfo);
									return false;
								}
								
							},
							"json"
						);	
					}else{
						return false;
					}
				}
			function isDelNull(){	
				var del_account = $("#del-username").val();
				var del_password = $("#del-password").val();
				if( del_account == "" || del_password == ""){
					if(del_account == ""){
						$("#span-account").html("用户名不能为空");
						 return false;
					}else{
						$("#span-account").html("");
					}
					if(del_password == ""){
						$("#span-password").html("密码不能为空");
						 return false;
					}else{
						$("#span-password").html("");
					}
				}else{
					return true;
				}
		}
			
			function isFind(){
				var username = $("#find-username").val();
//			    alert(username);
				if(username != "" ){
				$.post(
					"/cn.yl.caner/check",
					{"username": username },
					function(data){
						var isUsername = data.isUsername;
						var usernameInfo = "";
						if(isUsername){
							usernameInfo = "该用户存在";
						}else{
							usernameInfo = "该用户不存在"
								return false;
							$("#span-findusername").html(usernameInfo);
						}
						$("#span-findusername").html(usernameInfo);
					},
					"json"
				);	
				}else{
					
				}
			}
			
			function isFindNull(){	
				var find_account = $("#find-username").val();
				if( find_account == ""){
					if(find_account == ""){
						$("#span-findusername").html("用户名不能为空");
						 return false;
					}else{
						$("#span-findusername").html("");
					}
			
				}else{
					return true;
				}
		}			

		